package com.gitee.feizns.quickstart.ding.talk.api.v10.yida.forms.instances;

import com.aliyun.dingtalkyida_1_0.Client;
import com.aliyun.dingtalkyida_1_0.models.DeleteFormDataHeaders;
import com.aliyun.dingtalkyida_1_0.models.DeleteFormDataRequest;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;

/**
 * 删除表单数据（/v1.0/yida/forms/instances?formInstanceId=）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/delete-form-data">删除表单数据（/v1.0/yida/forms/instances?formInstanceId=）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/delete-form-data">服务端API 宜搭应用开发 表单 删除表单数据</a>
 * @author feizns
 * @since 2024/3/18
 */
public class DeleteById {

    /**
     * 根据表单实例编号删除表单实例数据
     * @param accessToken {@link String}
     * @param req {@link DeleteFormDataRequest}
     */
    @SneakyThrows
    public static void execute(@NotNull String accessToken,
                                 @NotNull DeleteFormDataRequest req) {
        Client client = Clients.get(Client.class);
        client.deleteFormDataWithOptions(req, headers(accessToken), new RuntimeOptions());
    }

    /**
     * 根据表单实例编号删除表单实例数据
     * @param accessToken 钉钉访问凭据
     * @param formInstanceId 表单实例ID。
     * @param appType 应用编码
     * @param systemToken 应用秘钥，在应用数据中获取。
     * @param userId 用户的userid。
     * @param language 语言，取值：zh_CN：中文（默认值）en_US：英文
     */
    public static void execute(@NotNull String accessToken,
                               @NotNull String formInstanceId,
                               @NotNull String appType,
                               @NotNull String systemToken,
                               @NotNull String userId,
                               @NotNull String language) {
        DeleteFormDataRequest req = new DeleteFormDataRequest();
        req.setAppType(appType);
        req.setSystemToken(systemToken);
        req.setUserId(userId);
        req.setLanguage(language);
        req.setFormInstanceId(formInstanceId);
        execute(accessToken, req);
    }

    /**
     * 请求头
     * @param accessToken 访问凭据
     * @return {@link DeleteFormDataHeaders}
     */
    public static DeleteFormDataHeaders headers(String accessToken) {
        DeleteFormDataHeaders headers = new DeleteFormDataHeaders();
        headers.xAcsDingtalkAccessToken = accessToken;
        return headers;
    }

}
